#ifndef _SDB_SIGNAL_H_
#define _SDB_SIGNAL_H_

/* 
 * Spinneret - Semi-Structured Database Engine
 * Copyright (c) 2009 Tom Bradford <spinneretdb.org>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */

/**
 * Wraps and abstracts basic signaling handling.  In POSIX, only one 
 * handler can be associated with any signal, the functions of this
 * library allow a chain of handlers to be associated with a signal.
 */

#include <stdbool.h>
#include <stdlib.h>

#include "main/common.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus


/** Incomplete type for Signal Handler instances */
typedef struct sdb_signal_t sdb_signal_t;

/** Function type for a Signal handler instance */
typedef sdb_status_t sdb_signal_function_t(sdb_signal_t* handler,
                                           void* context);
                                             
/** Create an Signal Handler instance */
sdb_signal_t* sdb_signal_new(int signalNumber, 
                                sdb_signal_function_t* handlerFunction,
                                void* context);

/** Returns the signal number associated with this Signal Handler instance */                              
int sdb_signal_getSignalNumber(sdb_signal_t* handler);

/** Sets the Handler function for the Signal Handler instance */
void sdb_signal_setHandlerFunction(sdb_signal_t* handler, 
                                   sdb_signal_function_t* handlerFunction);

/** Returns the Runnable function for the Signal Handler instance */
sdb_signal_function_t* sdb_signal_getHandlerFunction(sdb_signal_t* handler);

/** Sets the Context for the Signal Handler instance */
void sdb_signal_setContext(sdb_signal_t* handler, void* context);

/** Returns the Context for the Signal Handler instance */
void* sdb_signal_getContext(sdb_signal_t* handler);

/** Remove the Signal Handler instance from the handler chain */
void sdb_signal_remove(sdb_signal_t* handler);


#ifdef __cplusplus
}
#endif // __cplusplus

#endif // _SDB_SIGNAL_H_
